package com.cnap.multiclouldmgmt.model.vm;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cnap.multiclouldmgmt.model.scale.CreateScalingDTO;
import com.cnap.multiclouldmgmt.model.scale.db.ScalingPolicyPO;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 创建主机阶段的
 *
 * @author dyq
 */
@ApiModel(value = "com.cnap.multiclouldmgmt.model.vm.VmCreateModel", description = "虚拟机相关信息")
public class VmCreateModel {

    //微服务的名称
    @ApiModelProperty(value = "微服务的名称")
    private String svcName;

    //服务id
    @ApiModelProperty(value = "服务id")
    private String svcId;

    //当前步骤
    @ApiModelProperty(value = "当前步骤")
    private String type;

    //其他信息
    @ApiModelProperty(value = "其他信息")
    private List<Map<String, String>> extraInfo;

    //vm数据
    @ApiModelProperty(value = "vm数据")
    private List<VmModel> vmModels;

    //资源机器的json
    private String vmModelsJson;

    @ApiModelProperty(value = "errorMsg")
    private String errorMsg;

    //创建者
    @ApiModelProperty(value = "userName")
    private String userName;
    //打标
    private String category = "ai";
    //创建时间
    private Date createTime;

    //orderId
    @ApiModelProperty(value = "orderId")
    private String orderId;

    //userId
    @ApiModelProperty(value = "userId")
    private int userId;

    //createVmParam
    @ApiModelProperty(value = "createVmParam")
    private String createVmParam;

    @ApiModelProperty(value = "伸缩策略信息")
    private CreateScalingDTO createScalingDTO;

    @ApiModelProperty(value = "cpu还是gpu")
    private String arch;

    //accountName
    @ApiModelProperty(value = "accountName")
    private String accountName;

    //accountName
    @ApiModelProperty(value = "cloudScope 私有云还是公有云")
    private String cloudScope = "public";

    /**
     * get
     *
     * @return CloudScope
     */
    public String getCloudScope() {
        return cloudScope;
    }

    /**
     * set
     *
     * @param cloudScope cloudScope
     */
    public void setCloudScope(String cloudScope) {
        this.cloudScope = cloudScope;
    }

    /**
     *v1.5 是否是独立集群
     */
    private boolean forcedIsolation = false;

    // 二级分类序号
    private int order;
    // 二级分类
    private String detailType;

    //整个进程的步骤号
    private int stepOrder;

    //策略json串
    private String policyStr;

    private int forcedIsolationFlag = 0;

    //应用id
    private String appId;

    //等待的svc-id
    private String waitSvcId;

    /**
     * get
     *
     * @return SvcName
     */
    public String getSvcName() {
        return svcName;
    }

    /**
     * set
     *
     * @param svcName svcName
     */
    public void setSvcName(String svcName) {
        this.svcName = svcName;
    }

    /**
     * get
     *
     * @return WaitSvcId
     */
    public String getWaitSvcId() {
        return waitSvcId;
    }

    /**
     * set
     *
     * @param waitSvcId waitSvcId
     */
    public void setWaitSvcId(String waitSvcId) {
        this.waitSvcId = waitSvcId;
    }

    /**
     * get
     *
     * @return AppId
     */
    public String getAppId() {
        return appId;
    }

    /**
     * set
     *
     * @param appId appId
     */
    public void setAppId(String appId) {
        this.appId = appId;
    }

    /**
     * get
     *
     * @return StepOrder
     */
    public int getStepOrder() {
        return stepOrder;
    }

    /**
     * set
     *
     * @param stepOrder stepOrder
     */
    public void setStepOrder(int stepOrder) {
        this.stepOrder = stepOrder;
    }

    /**
     * get
     *
     * @return Order
     */
    public int getOrder() {
        return order;
    }

    /**
     * set
     *
     * @param order order
     */
    public void setOrder(int order) {
        this.order = order;
    }

    /**
     * get
     *
     * @return DetailType
     */
    public String getDetailType() {
        return detailType;
    }

    /**
     * set
     *
     * @param detailType detailType
     */
    public void setDetailType(String detailType) {
        this.detailType = detailType;
    }

    /**
     * get
     *
     * @return ForcedIsolation
     */
    public boolean isForcedIsolation() {

        if (forcedIsolationFlag == 1){
            forcedIsolation = true;
        }

        return forcedIsolation;
    }

    /**
     * set
     *
     * @param forcedIsolation forcedIsolation
     */
    public void setForcedIsolation(boolean forcedIsolation) {
        this.forcedIsolation = forcedIsolation;
    }

    /**
     * get
     *
     * @return createVmParam
     */
    public String getCreateVmParam() {
        return createVmParam;
    }

    /**
     * set
     *
     * @param createVmParam createVmParam
     */
    public void setCreateVmParam(String createVmParam) {
        this.createVmParam = createVmParam;
    }

    /**
     * get
     *
     * @return UserId
     */
    public int getUserId() {
        return userId;
    }

    /**
     * set
     *
     * @param userId userId
     */
    public void setUserId(int userId) {
        this.userId = userId;
    }

    /**
     * get
     *
     * @return Category
     */
    public String getCategory() {
        return category;
    }

    /**
     * set
     *
     * @param category category
     */
    public void setCategory(String category) {
        this.category = category;
    }

    /**
     * get
     *
     * @return OrderId
     */
    public String getOrderId() {
        return orderId;
    }

    /**
     * set
     *
     * @param orderId orderId
     */
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    /**
     * get
     *
     * @return CreateTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * set
     *
     * @param createTime createTime
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * get
     *
     * @return SvcId
     */
    public String getSvcId() {
        return svcId;
    }

    /**
     * set
     *
     * @param svcId svcId
     */
    public void setSvcId(String svcId) {
        this.svcId = svcId;
    }

    /**
     * get
     *
     * @return Type
     */
    public String getType() {
        return type;
    }

    /**
     * set
     *
     * @param type type
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * get
     *
     * @return ExtraInfo
     */
    public List<Map<String, String>> getExtraInfos() {
        return extraInfo;
    }

    /**
     * set
     *
     * @param extraInfo extraInfos
     */
    public void setExtraInfos(List<Map<String, String>> extraInfo) {
        this.extraInfo = extraInfo;
    }

    /**
     * get
     *
     * @return ExtraInfo
     */
    public List<Map<String, String>> getExtraInfo() {
        return extraInfo;
    }

    /**
     * set
     *
     * @param extraInfo extraInfo
     */
    public void setExtraInfo(List<Map<String, String>> extraInfo) {
        this.extraInfo = extraInfo;
    }

    /**
     * get
     *
     * @return VmModelsJson
     */
    public String getVmModelsJson() {

        if (StringUtils.isEmpty(vmModelsJson)
                && (vmModels != null)
                && (!vmModels.isEmpty())) {

            vmModelsJson = JSONObject.toJSONString(vmModels);
        }

        return vmModelsJson;
    }



    /**
     * set
     *
     * @param vmModelsJson vmModelsJson
     */
    public void setVmModelsJson(String vmModelsJson) {
        this.vmModelsJson = vmModelsJson;
    }

    /**
     * get
     *
     * @return VmModels
     */
    public List<VmModel> getVmModels() {

        if ((vmModels == null) || (vmModels.isEmpty())) {

            if (StringUtils.isNotEmpty(vmModelsJson)) {

                vmModels = JSONArray.parseArray(vmModelsJson, VmModel.class);
            }
        }

        return vmModels;
    }

    /**
     * set
     *
     * @param vmModels vmModels
     */
    public void setVmModels(List<VmModel> vmModels) {
        this.vmModels = vmModels;
    }

    /**
     * get
     *
     * @return ErrorMsg
     */
    public String getErrorMsg() {
        return errorMsg;
    }

    /**
     * set
     *
     * @param errorMsg errorMsg
     */
    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }


    /**
     * get
     *
     * @return UserName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * set
     *
     * @param userName userName
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * get
     *
     * @return CreateScalingDTO
     */
    public CreateScalingDTO getCreateScalingDTO() {

        if (StringUtils.isNotEmpty(policyStr)){
            createScalingDTO  = JSON.parseObject(policyStr,CreateScalingDTO.class);

        }

        return createScalingDTO;    }

    /**
     * set
     *
     * @param createScalingDTO createScalingDTO
     */
    public void setCreateScalingDTO(CreateScalingDTO createScalingDTO) {
        this.createScalingDTO = createScalingDTO;
    }

    /**
     * get
     *
     * @return PolicyStr
     */
    public String getPolicyStr() {

        if (createScalingDTO != null){
            policyStr = JSON.toJSONString(createScalingDTO);
        }

        return policyStr;
    }

    /**
     * set
     *
     * @param policyStr policyStr
     */
    public void setPolicyStr(String policyStr) {
        this.policyStr = policyStr;
    }

    /**
     * get
     *
     * @return ForcedIsolationFlag
     */
    public int getForcedIsolationFlag() {
        if (forcedIsolation){
            forcedIsolationFlag = 1;
        }
        return forcedIsolationFlag;
    }

    /**
     * set
     *
     * @param forcedIsolationFlag forcedIsolationFlag
     */
    public void setForcedIsolationFlag(int forcedIsolationFlag) {
        this.forcedIsolationFlag = forcedIsolationFlag;
    }

    /**
     * get
     *
     * @return Arch
     */
    public String getArch() {
        return arch;
    }

    /**
     * set
     *
     * @param arch arch
     */
    public void setArch(String arch) {
        this.arch = arch;
    }

    /**
     * get
     *
     * @return AccountName
     */
    public String getAccountName() {
        return accountName;
    }

    /**
     * set
     *
     * @param accountName accountName
     */
    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }
}
